package com.example.demo.controller.impor;

import cn.hutool.json.JSONUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

@Slf4j
@Service
@RequiredArgsConstructor
public class ImportService {
//    private final MemberMapper memberMapper;
//    private final AccountNameMapper accountNameMapper;
//    private final PhoneNumberMapper phoneNumberMapper;
//    private final TokenInfoMapper tokenInfoMapper;

    @Transactional
    public void importData(InputStream excelFile) throws IOException {
        List<UserExcelData> excelData = ExcelReader.readExcel(excelFile);
//        for (UserExcelData data : excelData) {
//            // 检查用户是否存在
//            if (memberMapper.findIdByName(data.getUser()) != null) {
//                throw new RuntimeException("用户已存在: " + data.getUser());
//            }
//
//            // 插入用户
//            Member member = new Member();
//            member.setName(data.getUser());
//            member.setMemberName(""); // 根据需求调整
//            memberMapper.insert(member);
//
//            // 插入关联表
//            Long memberId = member.getId();
//            accountNameMapper.insert(new AccountName(memberId, data.getUser()));
//            phoneNumberMapper.insert(new PhoneNumber(memberId, data.getContact()));
//            tokenInfoMapper.insert(new TokenInfo(memberId, generateToken()));
//        }
        log.info("ImportService--->importData--->excelData:{}", JSONUtil.toJsonStr(excelData));
    }

//    private String generateToken() {
//        return UUID.randomUUID().toString().replace("-", "");
//    }
}
